package com.huawei.esdk.uc.device.u19.callback.convert;

import com.huawei.ecs.bin.service.NotiAtte;
import com.huawei.ecs.bin.service.NotiConf;
import com.huawei.ecs.bin.service.data.Atte.AtteStatus;
import com.huawei.ecs.bin.service.data.Conf.ConfState;
import com.huawei.esdk.platform.common.utils.JAXBUtils;
import com.huawei.esdk.uc.device.u19.callback.bean.CTCConfState;
import com.huawei.esdk.uc.device.u19.callback.bean.CTCUserState;
import com.huawei.esdk.uc.device.u19.callback.bean.ConfStateBean;
import com.huawei.esdk.uc.device.u19.callback.bean.UserStateBean;

public class NotifyCapabilityConvert
{
    public String getConfStatusObj2String(NotiConf notiConf)
    {
        if (null == notiConf)
        {
            return null;
        }
        
        ConfStateBean bean = new ConfStateBean();
        bean.setConfId(notiConf.conf_.conferId_);
        bean.setStatus(getConfStatusEnum2Str(notiConf.conf_.state_));
        
        CTCConfState confState = new CTCConfState();
        confState.setBean(bean);
        
        String inMsg = JAXBUtils.bean2Xml(confState);
        
        return inMsg;
    }
    
    public String getAtteStatusObj2String(NotiAtte notiAtte)
    {
        if (null == notiAtte)
        {
            return null;
        }
        
        UserStateBean bean = new UserStateBean();
        bean.setConfId(notiAtte.atte_.confId_);
        bean.setCee(notiAtte.atte_.attendNum_);
        bean.setStatus(getAtteStatusEnum2Str(notiAtte.atte_.attendStatus_));
        
        CTCUserState userState = new CTCUserState();
        userState.setBean(bean);
        
        String inMsg = JAXBUtils.bean2Xml(userState);
        
        return inMsg;
    }
    
    private String getConfStatusEnum2Str(ConfState confState)
    {
        if (null == confState)
        {
            return null;
        }
        
        Integer value = confState.value();
        
        switch (value)
        {
            case 0:
                return "IDLE";
            case 1:
                return "CREATED";
            case 2:
                return "INVITINT";
            case 3:
                return "MEETING";
            case 4:
                return "ALLOC_RESOURCE";
            case 5:
                return "RELEASEGUARD";
            case -1:
                return "UNKNOWN";
            default:
                return null;
        }
    }
    
    private String getAtteStatusEnum2Str(AtteStatus atteStatus)
    {
        if (null == atteStatus)
        {
            return null;
        }
        
        Integer value = atteStatus.value();
        
        switch (value)
        {
            case 0:
                return "LEAVE";
            case 1:
                return "CALLING";
            case 2:
                return "CONNECTING";
            case 3:
                return "MEETING";
            case 4:
                return "WAIT_OTHER_ATTENDEE";
            case -1:
                return "UNKNOWN";
            default:
                return null;
        }
    }
    
}
